package com.snake.springboot.authority.web.controller;

import com.snake.springboot.authority.api.model.AuthRoleMenuModel;
import com.snake.springboot.authority.api.request.AuthRoleMenuSave;
import com.snake.springboot.authority.api.service.AuthRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.snake.common.result.ResponseResult;
import org.snake.common.result.ResponseResultFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 类 {@code AuthMenuStrategyController}  <br> .
 * <p>权限管理-角色与菜单关系
 * 创建时间：2024/6/4 10:25
 *
 * @author Yzhui
 * @see
 */
@Api(tags = "权限管理-角色与菜单关系")
@RestController
@RequestMapping("/auth/menu-strategy")
public class AuthRoleMenuRefController {

    private AuthRoleMenuService authRoleMenuService;

    @Autowired
    public AuthRoleMenuRefController(AuthRoleMenuService authRoleMenuService) {
        this.authRoleMenuService = authRoleMenuService;
    }

    @ApiOperation("查询角色与菜单关系列表")
    @GetMapping("/query/{roleid}")
    public ResponseResult<List<AuthRoleMenuModel>> queryRoleMenuRefList(
            @ApiParam(name = "权限角色ID", value = "传入String格式", required = true)
            @PathVariable("roleid") String roleId) throws Exception {
        List<AuthRoleMenuModel> result = authRoleMenuService.queryRoleMenuRef(roleId);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

    @ApiOperation("查询角色与菜单关系列表")
    @PostMapping("/list")
    public ResponseResult<List<AuthRoleMenuModel>> queryRoleMenuRefList(
            @ApiParam(name = "角色权限入参", value = "传入String格式", required = true)
            @RequestBody AuthRoleMenuModel model){
        List<AuthRoleMenuModel> result = authRoleMenuService.queryRoleMenuRef(model);
        return ResponseResultFactory.ucc("查询成功！", result);
    }

    @ApiOperation("保存角色与菜单关系")
    @PostMapping("/save")
    public ResponseResult<AuthRoleMenuModel> saveAuthMenuStrategy(
            @ApiParam(name = "权限角色与菜单关系列表", value = "传入json格式", required = true)
            @RequestBody AuthRoleMenuSave params){
        authRoleMenuService.saveRoleMenuRef(params);
        return ResponseResultFactory.ucc("保存成功！");
    }

}
